#include "common.h"
#include "networkessential.h"
#include "messageCommon.h"

messageCommon::messageCommon(const std::string &sendername, unsigned int type)
	:messageBase(type),
	 m_sendername(sendername)
{}

void messageCommon::generateMessage(std::string &buf) const
{
	// Message content:
	// messagetype message_len sendername_len sendername

	unsigned int messagetype = m_messagetype;
	int message_len;
	int sendername_len = m_sendername.size();

	message_len = IntLength + sendername_len;

	buf.append(FourBytesToNetChar(messagetype), IntLength);
	buf.append(FourBytesToNetChar(message_len), IntLength);
	buf.append(FourBytesToNetChar(sendername_len), IntLength);
	buf.append(m_sendername);
}
